package models

import scala.collection.mutable.ListBuffer

case class Account(id: Int, email: String, password: String, name: String, role: Seq[Role])

object Account {
  private val admin: Account =  Account(1, "alice@gmail.com", "bluesky", "bluesky", List(Role.Administrator, Role.NormalUser))
  private val noAuth: Account =  Account(2, "bluesky@gmail.com", "bluesky", "bluesky", List(Role.NormalUser))
  val accounts =  ListBuffer(admin, noAuth)


  def authenticate(email: String, password: String): Option[Account] = findByEmail(email).filter(_.password==password)


  def findByEmail(email: String): Option[Account] = accounts.filter(_.email == email).headOption

  def findById(id: Int): Option[Account] = accounts.filter(_.id == id).headOption

  def findAll(): Seq[Account] = accounts

  def create(account: Account) {
    accounts.+=(account)
  }

}
